package com.huiquan.check_sentence.dao;

import com.huiquan.analysis.domain.AnalysisSentence;
import com.huiquan.analysis.domain.AnalysisVocabulary;
import com.huiquan.framework.base.BaseDao;
import com.ibatis.sqlmap.client.SqlMapClient;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lichao email:lichao@witspring.com
 * @Description:
 * @Date 2017/12/1 11:04
 * @since Ver V
 */
@Repository
public class CheckSentenceDao extends BaseDao {
    @Resource(name = "sqlMapClient")
    private SqlMapClient sqlMapClient;

    public static final String space = "CHECK_SENTENCE.";

    /**
     * 检索得到句子数量
     *
     * @param param
     * @return
     */
    public Integer selectCheckSentenceCount(Map<String, Object> param) {
        return (Integer) this.object(space + "SELECT_CHECK_SENTENCE_COUNT", param, sqlMapClient);
    }

    /**
     * 检索得到句子列表
     *
     * @param param
     * @return
     */
    @SuppressWarnings("unchecked")
    public List<AnalysisSentence> selectCheckSentenceList(Map<String, Object> param) {
        return (List<AnalysisSentence>) this.list(space + "SELECT_CHECK_SENTENCE_LIST", param, sqlMapClient);
    }

    /**
     * 根据sid得到外包数据id列表
     *
     * @param sid
     * @return
     */
    @SuppressWarnings("unchecked")
    public List<Long> selectOsidList(long sid) {
        return (List<Long>) this.list(space + "SELECT_OSID_LIST", sid, sqlMapClient);
    }

    /**
     * 根据osid得到外包人员标记的语句
     *
     * @param osid
     * @return
     */
    @SuppressWarnings("unchecked")
    public List<AnalysisVocabulary> selectOutsourcingVocabularyByOsid(long osid) {
        return (List<AnalysisVocabulary>) this.list(space + "SELECT_OUTSOURCING_VOCABULARY_BY_OSID", osid, sqlMapClient);
    }

    /**
     * 更新分包语句的状态
     *
     * @param sid
     * @param status
     */
    public void updateOutsourcingSentenceStatus(long sid, int status) {
        Map<String, Object> params = new HashMap<>();
        params.put("sid", sid);
        params.put("status", status);
        this.update(space + "UPDATE_OUTSOURCING_SENTENCE_STATUS", params, sqlMapClient);
    }

    /**
     * 更新分包分词的正误flag
     *
     * @param id
     * @param flag
     */
    public void updateOutsourcingVocabularyFlag(long id, int flag) {
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        params.put("flag", flag);
        this.update(space + "UPDATE_OUTSOURCING_VOCABULARY_FLAG", params, sqlMapClient);
    }
}
